import { CacheService } from '@app/cache';
import { WechatService } from '@app/wechat';
import { Injectable, OnModuleInit } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { Cron } from '@nestjs/schedule';

@Injectable()
export class ScheduleService implements OnModuleInit {
	constructor(
		private readonly cache:CacheService,
		private readonly wechat:WechatService,
		private readonly config:ConfigService,
	){}

	onModuleInit() {
		this.getWxAccessToken()
	}

	@Cron('0 * * * *')
	getWxAccessToken() {
		this.wechat.getWXAccessToken().then(r => {
			console.log(r)
			if(r) {
				this.cache.set(this.config.get('WX_ACCESS_TOKEN_KEY'), r)
			}
			
		})
	}

}
